// pages/index/adminIndex/adminIndex.js

Component({

  /**
   * 页面的初始数据
   */
  data: {

    option1: [{
      text: '管理员',
      value: 3
    }, ],
    option2: [{
        text: '全部统计',
        value: 'a'
      },
      {
        text: '今日统计',
        value: 'b'
      }
    ],
    value1: 3,
    value2: 'a',
    count: null,
    loading: false,
    TodayLeaveList:null,
    TodaySignList:null
  },
  methods: {
    // 获取统计接口
    async getTotalCount() {
      const userInfo = getApp().globalData.userInfo
      const uid = userInfo.id
      const school_ID = userInfo.school_ID
      this.setData({
        loading: true
      })
      this.triggerEvent('EV_loading', {
        loading: true
      })
      let code = "/getAdminIndex"
      // let code = "/getAdminIndex?is_today="+this.data.value2
      try {
        const params = {
          uid,
          school_ID,
          is_today:this.data.value2
        }
        // const json = await getApp().$axios(code, 'GET');
        const json = await getApp().$axios(code, 'POST',params);
        this.setData({
          loading: false
        })
        this.triggerEvent('EV_loading', {
          loading: false
        })
        if (json.status !== 200) {
          wx.showToast({
            title: '获取统计数据异常',
            icon: 'none'
          })
          return
        }
        this.setData({
          count: json.data
        })
      } catch (error) {
        wx.showToast({
          title: error.msg,
          icon: 'error'
        })
      }
    },
    change(e) {
      this.setData({
        value2: e.detail
      })
      this.getTotalCount()
    },
    // 获取今日请假人信息
    async getHolidayInfo() {
      let code = "/getTodayLeaveList?school_ID="+getApp().globalData.userInfo.school_ID
      try {
        const json = await getApp().$axios(code, 'GET');
        if (json.status !== 200) {
          wx.showToast({
            title: '获取统计数据异常',
            icon: 'none'
          })
          return
        }
        this.setData({
          TodayLeaveList:json.data
        })
      } catch (error) {
        wx.showToast({
          title: error.msg,
          icon: 'error'
        })
      }
    },
    // 获取今日未签到人
    async getTodayNoSignList() {
      let code = "/getTodayNoSignList?school_ID="+getApp().globalData.userInfo.school_ID
      try {
        const json = await getApp().$axios(code, 'GET');
        if (json.status !== 200) {
          wx.showToast({
            title: '获取统计数据异常',
            icon: 'none'
          })
          return
        }
        this.setData({
          TodaySignList:json.data
        })
      } catch (error) {
        wx.showToast({
          title: error.msg,
          icon: 'error'
        })
      }
    },
  },
  properties: {},
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.getTodayNoSignList()
      this.getHolidayInfo()
      this.getTotalCount()
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  // 组件在页面中的生命周期
  pageLifetimes: {
    show: function () {
      this.getTodayNoSignList()
      this.getHolidayInfo()
      this.getTotalCount()
    },
    hide: function () {
      // 页面被隐藏
    },
    resize: function (size) {
      // 页面尺寸变化
    }
  }

})